---
title: Media Trend Analysis Agent
---
The Media Trend Analysis Agent Example demonstrates a sophisticated AI-powered tool designed to analyze media trends, track digital conversations, and provide actionable insights across various online platforms. This agent combines web search capabilities with content scraping to deliver comprehensive trend analysis reports.

### What It Does

This agent specializes in:
- **Trend Identification**: Detects emerging patterns and shifts in media coverage
- **Source Analysis**: Identifies key influencers and authoritative sources
- **Data Extraction**: Gathers information from news sites, social platforms, and digital media
- **Insight Generation**: Provides actionable recommendations based on trend analysis
- **Future Forecasting**: Predicts potential developments based on current patterns

### Key Features

- **Multi-Source Analysis**: Combines Exa search tools with Firecrawl scraping capabilities
- **Intelligent Filtering**: Uses keyword-based searches with date filtering for relevant results
- **Smart Scraping**: Only scrapes content when search results are insufficient
- **Structured Reporting**: Generates comprehensive markdown reports with executive summaries
- **Real-time Data**: Analyzes current trends with configurable time windows

## Code

```python cookbook/examples/agents/media_trend_analysis_agent.py
"""Please install dependencies using:
pip install openai exa-py agno firecrawl
"""

from datetime import datetime, timedelta
from textwrap import dedent

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.exa import ExaTools
from agno.tools.firecrawl import FirecrawlTools


def calculate_start_date(days: int) -> str:
    """Calculate start date based on number of days."""
    start_date = datetime.now() - timedelta(days=days)
    return start_date.strftime("%Y-%m-%d")


agent = Agent(
    model=OpenAIChat(id="gpt-5-mini"),
    tools=[
        ExaTools(start_published_date=calculate_start_date(30), type="keyword"),
        FirecrawlTools(scrape=True),
    ],
    description=dedent("""\
        You are an expert media trend analyst specializing in:
        1. Identifying emerging trends across news and digital platforms
        2. Recognizing pattern changes in media coverage
        3. Providing actionable insights based on data
        4. Forecasting potential future developments
    """),
    instructions=[
        "Analyze the provided topic according to the user's specifications:",
        "1. Use keywords to perform targeted searches",
        "2. Identify key influencers and authoritative sources",
        "3. Extract main themes and recurring patterns",
        "4. Provide actionable recommendations",
        "5. if got sources less then 2, only then scrape them using firecrawl tool, dont crawl it  and use them to generate the report",
        "6. growth rate should be in percentage , and if not possible dont give growth rate",
    ],
    expected_output=dedent("""\
    # Media Trend Analysis Report

    ## Executive Summary
    {High-level overview of findings and key metrics}

    ## Trend Analysis
    ### Volume Metrics
    - Peak discussion periods: {dates}
    - Growth rate: {percentage or dont show this}

    ## Source Analysis
    ### Top Sources
    1. {Source 1}

    2. {Source 2}


    ## Actionable Insights
    1. {Insight 1}
       - Evidence: {data points}
       - Recommended action: {action}

    ## Future Predictions
    1. {Prediction 1}
       - Supporting evidence: {evidence}

    ## References
    {Detailed source list with links}
    """),
    markdown=True,
    add_datetime_to_context=True,
)

# Example usage:
analysis_prompt = """\
Analyze media trends for:
Keywords: ai agents
Sources: verge.com ,linkedin.com, x.com
"""

agent.print_response(analysis_prompt, stream=True)

# Alternative prompt example
crypto_prompt = """\
Analyze media trends for:
Keywords: cryptocurrency, bitcoin, ethereum
Sources: coindesk.com, cointelegraph.com
"""

# agent.print_response(crypto_prompt, stream=True)

```
## Usage

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Set your API key">
    ```bash
    export OPENAI_API_KEY=xxx
    export EXA_API_KEY=xxx
    export FIRECRAWL_API_KEY=xxx
    ```
  </Step>

  <Step title="Install libraries">
    ```bash
    pip install -U agno openai exa-py agno firecrawl
    ```
  </Step>

  <Step title="Run Agent">
    <CodeGroup>
    ```bash Mac
    python cookbook/examples/agents/media_trend_analysis_agent.py
    ```

    ```bash Windows
    python cookbook/examples/agents/media_trend_analysis_agent.py
    ```
    </CodeGroup>
  </Step>
</Steps>

## Customization Options

You can customize the agent's behavior by:
- **Adjusting Time Windows**: Modify the `calculate_start_date()` function to analyze different time periods
- **Adding Sources**: Include additional websites or platforms in your analysis prompts
- **Modifying Keywords**: Change search terms to focus on specific topics or industries
- **Customizing Output**: Modify the `expected_output` template to match your reporting needs

## Example Prompts

Here are some additional prompt examples you can try:

```python
# Technology trends
tech_prompt = """\
Analyze media trends for:
Keywords: artificial intelligence, machine learning, automation
Sources: techcrunch.com, arstechnica.com, wired.com
"""

# Business trends
business_prompt = """\
Analyze media trends for:
Keywords: remote work, digital transformation, sustainability
Sources: forbes.com, bloomberg.com, hbr.org
"""

# Entertainment trends
entertainment_prompt = """\
Analyze media trends for:
Keywords: streaming, gaming, social media
Sources: variety.com, polygon.com, theverge.com
"""
```
